const express=require("express")
const router=express.Router();
const pool=require("../pool");

router.get("/",(req,res)=>{
  //查询文章列表
  //1:获取参数
  var id=req.query.nid;
  //2:创建正则表达式
  var reg = /^\d{1,}$/;
  //3:如果验证失败 输出错误信息{code:-1}
  if(!reg.test(id)){
    res.send({code:-1,msg:"新闻标号格式有误"});
    return;
  }
  var sql="select nid,userimg,user,dates,readNum,title,content FROM news_detail WHERE nid=?";
  pool.query(sql,[id],(err,result)=>{
    if(err) console.log(err);
    //console.log(result);
    res.send({code:1,data:result});
  })
})
module.exports=router;